﻿#pragma once

#include <QtWidgets/QMainWindow>
#include <QtCore/QTimer>
#include <QtWidgets/QLabel>
#include "ui_CanAnalyzeTest.h"

#include "ControlCAN/ControlCAN.h"


#include "QtChCharset.h"


enum StatusBarMsgColor {
	StatusBarMsgColor_Black,
	StatusBarMsgColor_Green,
	StatusBarMsgColor_Blue,
	StatusBarMsgColor_Red,
};



class CanAnalyzeTest : public QMainWindow
{
	Q_OBJECT

public:
	CanAnalyzeTest(QWidget *parent = Q_NULLPTR);
private:
	// 状态栏
	void createStatusBar();
	QLabel * mpLabelStatusTx = nullptr;
	QLabel * mpLabelStatusRx = nullptr;
public Q_SLOTS:
	void on_btnOpenCan_clicked();
	void on_btnClearTxData_clicked();
	void on_btnTxDataPause_clicked();

	void on_btnSend_clicked();
	void on_checkBoxSendHex_clicked();

	void timeoutReceive();


	// 状态栏显示消息
	void SlotStatusBarMessage(QString strMessage, StatusBarMsgColor iLevel = StatusBarMsgColor_Black, int iTimeoutMs = 8000);
protected:
	// Event handlers
	virtual void wheelEvent(QWheelEvent *event);
private:
	QTimer mReceiveTimer;
	QString mstrPortData;
	int miEditTextLength = 0;

	int nDeviceType = 4; /* USBCAN-2A或USBCAN-2C或CANalyst-II */
	int nDeviceInd = 0; /* 第1个设备 */
	int nCANInd = 1; /* 通道， 0：通道1。1：通道2 */

	// 发送接收计数
	unsigned int miTxByteCount = 0;
	unsigned int miTxPacketCount = 0;
	unsigned int miRxByteCount = 0;
	unsigned int miRxPacketCount = 0;

	// 暂停接收数据
	bool mbTxDataPause = false;

	// 接收的数据
	std::vector<unsigned char> mReceiveDataVec;
private:
	Ui::CanAnalyzeTestClass ui;
};
